
var pageIndex = 0;//页面索引初始值  
 var pageSize = 10;     //每页显示条数初始化，修改显示条数，修改这里即可  
 var pageActionPath;

var initPagination=function(data){
  queryaginationa();
};
function queryByCon(path,showDom){
	pageActionPath = path;
	loadInitByCon(pageActionPath,showDom);
	$("#"+showDom).show();
}

function query(path){
	pageActionPath = path;
	loadInit(pageActionPath);
	$("#Searchresult").show();
}
function loadInitByCon(actionPath,showDom){
	var pageParam = {currentPage:pageIndex,pageSize:pageSize};
	var businessParam = $("#businessForm").serializeJson();
	var pageParam = $.extend({}, pageParam,businessParam);
	loadResultByCon(pageParam,showDom);
}
function loadInit(actionPath){
	var pageParam = {currentPage:pageIndex,pageSize:pageSize};
	var businessParam = $("#businessForm").serializeJson();
	 var pageParam = $.extend({}, pageParam,businessParam);
 	loadResult(pageParam);
}

function queryaginationa(){
 var totalPage = $('#totalRow').val();
 var optInit = getOptionsFromForm();
 $("#Paginationa").pagination(totalPage, optInit);
  if (totalPage < 1) {
			$("#Paginationa").hide();
		}else{
			$("#Paginationa").show();
		}
}
 
 function getOptionsFromForm(){
    var opt = {callback: pageselectCallback};
    opt['items_per_page']=pageSize;
    opt['num_display_entries']=5;
    opt['num_edge_entries']=2;
    opt['prev_text']='上一页';
    opt['next_text']='下一页';
    opt['current_page']=pageIndex;
    return opt;
}

function pageselectCallback(page_index, jq){
	pageIndex = page_index;
	var pageParam = {currentPage:pageIndex,pageSize:pageSize};
	var businessParam = $("#businessForm").serializeJson();
	 var pageParam = $.extend({}, pageParam,businessParam);
	loadResult(pageParam);
	return false;
}	
/**
 * 设置首页、尾页 颜色
 * topPageId 首页id
 * endPageId 尾页id
 * endPageIndex 尾页页码索引
**/
function setPageColor(topPageId,endPageId,totalPage){
	//首页时，尾页设置颜色

	if(pageIndex==0){
		//$(".prev span").removeAttr("class","current");
		$("#"+topPageId).attr("class","current");
		$("#"+endPageId).removeAttr("class","current");
		//$(".next a").attr("class","current");
	}else if(pageIndex==(totalPage-1)){
	//尾页时，首页设置颜色
		$("#"+topPageId).removeAttr("class","current");
		$("#"+endPageId).attr("class","current");
	}else{
		$("#topPage").removeAttr("class","current");
		$("#"+endPageId).removeAttr("class","current");
	}
}

function loadResultByCon(pageParam,sowDom){
	$("#"+sowDom).load(pageActionPath, 
			pageParam,initPagination);
//设置页面页码			
//$("#pageCodeId").text(pageIndex+1);
//设置首页、尾页 颜色
	var totalPage = $("#totalPage").val();
	
	setPageColor("topPage","endPage",totalPage);
}
function loadResult(pageParam){
$("#Searchresult").load(pageActionPath, 
			pageParam,initPagination);
//设置页面页码			
//$("#pageCodeId").text(pageIndex+1);
//设置首页、尾页 颜色
var totalPage = $("#totalPage").val();

setPageColor("topPage","endPage",totalPage);
}